package com.plian.system.service.transfer.impl;

import com.plian.Tools.CollectionUtil;
import com.plian.system.service.transfer.ITransferFlowService;
import com.plian.system.service.wf.WorkFlowFormService;
import com.plian.system.service.wf.WorkflowService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class TransferFlowServiceImpl implements ITransferFlowService {

    private WorkflowService workFlowService;

    private WorkFlowFormService workFlowFormService;

    @Override
    public void submit(List<String> submitIds, int formType) {
        if (CollectionUtil.isNotEmpty(submitIds)){
            for (String id : submitIds) {
                try {
                    HashMap<String, Object> workflowVariables = workFlowFormService.submit(formType, id);
                    workFlowService.submit(id, formType, workflowVariables);
                } catch (Exception e) {
                    log.error(ExceptionUtils.getFullStackTrace(e));
                }
            }
        }
    }
}
